# remotes::install_github("rCarto/cobweb")
library(cobweb)
cobweb(city = "Mainz, Germany", nroad = 3000, ncl = 6)How to Build an European-Wide OSRM Server on a Desktop Computer
OSRM
Open Source Routing Machine, or OSRM (Luxen and Vetter 2011), is a routing software based on OpenStreetMap (OSM) data. OSRM can be use to find the fastest route between points, to compute time or distance matrices between set of points or to solve the traveling salesman problem.
As maintainer of the osrm R package (Giraud 2022) I often find myself advising users to use their own instance of OSRM to enable them to send a large number of requests and not overload the demo server. In these cases I simply point to the Docker installation instructions in the project’s README file. These instructions may not be detailed enough to build an OSRM instance on a large area.
OSRM needs a lot of RAM to prepare the road network for requests and using only these instructions will probably result in message like this one:
[warn] Please provide more memory or consider using a larger swapfileIn this post I’ll explain how to build and European-wide OSRM instance on a desktop computer. These explanations are, to a certain extent, also valid when using a remote server.
This post implies some Linux/CLI/Docker knowledge from its reader.
Hardware
I use my personal laptop computer which has a 1To SSD hard drive and the following config:
OS: Debian GNU/Linux 12 (bookworm) x86_64 Host: HP EliteBook 840 G8 Notebook PC Kernel: 6.1.0-10-amd64 CPU: 11th Gen Intel i7-1185G7 (8) @ 4.800GHz Memory: 31.04GiB
Add some extra memory
The preparation of the OSM network for OSRM is memory intensive and will need more than the already available 32Go of RAM. The swap memory is used when a program consume the totality of the available RAM memory. Consequently we need to extend the swap memory of our computer. I use a very large file to be sure to not exceed the limit.
sudo fallocate -l 200G swap.swap
sudo chmod 600 swap.swap
sudo mkswap swap.swap
sudo swapon swap.swap
sudo sysctl vm.swappiness=20Download the OSM road network
The Geofabrik website provides OSM database extracts that can be used as input for OSRM. In our case we have downloaded the osm.pbf file for Europe (27.1 GB).
Build the dataset for OSRM
The europe-latest.osm.pbf file needs to be processed to be used by OSRM. This is done in three steps.
- Extract (~5h30)
docker run -t -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend:v5.27.1 osrm-extract -p /opt/car.lua /data/europe-latest.osm.pbf- Partition (~1h20)
docker run -t -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend:v5.27.1 osrm-partition /data/europe-latest.osrm- Customize (~0h10)
docker run -t -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend:v5.27.1 osrm-customize /data/europe-latest.osrmRun the instance
This is the command I use to run this freshly built OSRM instance:
docker run --rm -t -i -p 5000:5000 -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend:v5.27.1 osrm-routed --algorithm mld --max-table-size 50000000 /data/europe-latest.osrmExample of use
This OSRM instance will actually be used in the framework of an European research program (Granular). In this project we’ll need to request a very large number of distances and routes throughout Europe in order to create relevant accessibility indicators for rural areas.
I built a small R package relying on osrm to send queries in a parallel fashion and create “All roads lead to …” maps. The cobweb package is not bulletproof and it is not on CRAN.
Here is a small demo:
Another experiment
step1 2023-10-05 14:55 2023-10-07 22:48
step 2 2023-10-09 09:06 2023-10-09 11:44
step 3 2023-10-09 12h26 2023-10-09 13h24